home *** CD-ROM | disk | FTP | other *** search
/ EnigmA Amiga Run 1999 March / EnigmA AMIGA RUN 35 (1999)(G.R. Edizioni)(IT)[!][issue 1999-03].iso / earcd / grafica / amhelios / p_clip4.h < prev    next >
C/C++ Source or Header  |  1999-01-01  |  3KB  |  85 lines

  1. ////////////////////////////////////////////////////////////
  2. //
  3. //  P_CLIP4.H - 4-D Polygon Clipper Class
  4. //
  5. //  Version:    1.03A
  6. //
  7. //  History:    94/08/23 - Version 1.00A release.
  8. //              94/12/16 - Version 1.01A release.
  9. //              95/02/05 - Version 1.02A release.
  10. //              95/07/21 - Version 1.02B release.
  11. //              96/02/14 - Version 1.02C release.
  12. //              96/04/01 - Version 1.03A release.
  13. //
  14. //  Compilers:  Microsoft Visual C/C++ Professional V1.5
  15. //              Borland C++ Version 4.5
  16. //
  17. //  Author:     Ian Ashdown, P.Eng.
  18. //              byHeart Software Limited
  19. //              620 Ballantree Road
  20. //              West Vancouver, B.C.
  21. //              Canada V7S 1W3
  22. //              Tel. (604) 922-6148
  23. //              Fax. (604) 987-7621
  24. //
  25. //  Copyright 1994-1996 byHeart Software Limited
  26. //
  27. //  The following source code has been derived from:
  28. //
  29. //    Ashdown, I. 1994. Radiosity: A Programmer's
  30. //    Perspective. New York, NY: John Wiley & Sons.
  31. //
  32. //  It may be freely copied, redistributed, and/or modified
  33. //  for personal use ONLY, as long as the copyright notice
  34. //  is included with all source code files.
  35. //
  36. ////////////////////////////////////////////////////////////
  37.  
  38. #ifndef _P_CLIP4_H
  39. #define _P_CLIP4_H
  40.  
  41. #include "out_poly.h"
  42.  
  43. enum Plane { Front, Back, Left, Right, Top, Bottom };
  44.  
  45. class ClipEdge              // Edge-plane clipper
  46. {
  47.   private:
  48.     ClipEdge *pnext;        // Next clipper pointer
  49.     Vector4 normal;         // Plane normal
  50.     Vertex4 first;          // First vertex
  51.     Vertex4 start;          // Start vertex
  52.     BOOL first_inside;      // First vertex inside flag
  53.     BOOL start_inside;      // Start vertex inside flag
  54.     BOOL first_flag;        // First vertex seen flag
  55.  
  56.     BOOL IsInside( Vertex4 &v )
  57.     { return (Dot(normal, v.GetCoord()) >= 0.0); }
  58.     Vertex4 Intersect( Vertex4 &, Vertex4 & );
  59.     void Output( Vertex4 &, OutPolygon & );
  60.  
  61.   public:
  62.     ClipEdge() { first_flag = FALSE; }
  63.  
  64.     void Add( ClipEdge *pc ) { pnext = pc; }
  65.     void Clip( Vertex4 &, OutPolygon & );
  66.     void Close( OutPolygon & );
  67.     void SetNormal( Vector4 &n ) { normal = n; }
  68. };
  69.  
  70. class PolyClip4             // 4-D polygon clipper
  71. {
  72.   private:
  73.     int num_vert;           // Number of output vertices
  74.     ClipEdge clipper[6];    // Clipper array
  75.     ClipEdge *pclip;        // Clipper list head pointer
  76.  
  77.   public:
  78.     PolyClip4();
  79.  
  80.     int Clip( Element3 *, OutPolygon &, double (*)[4] );
  81. };
  82.  
  83. #endif
  84.  
  85.